package logic

import (
	"context"
	"github.com/pkg/errors"
	"mall/app/product/cmd/rpc/pb"
	"mall/common/xerr"

	"mall/app/product/cmd/api/internal/svc"
	"mall/app/product/cmd/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetAttrGroupInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetAttrGroupInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAttrGroupInfoLogic {
	return &GetAttrGroupInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetAttrGroupInfoLogic) GetAttrGroupInfo(req *types.GetAttrGroupInfoReq) (*pb.GetAttrGroupInfoResp, error) {
	info, err := l.svcCtx.ProductRpc.GetAttrGroupInfo(l.ctx, &pb.GetAttrGroupInfoReq{AttrGroupId: req.AttrGroupId})
	if err != nil {
		logx.Errorf("err: %v", err)
		return nil, errors.Wrapf(xerr.NewErrorWithMsg("获取属性分组信息失败"), "req: %+v, err: %v", req, err)
	}
	return info, nil
}
